<?php
/**
 * Hols class Image_Lib_LookUpFilter
 *
 * @author daantimmer
 *
 * @package Library
 * @subpackage Image
 */

/**
 * LookUp Table Filter callback function.
 *
 * This class was first designed in Java using an abstract LookUpFilter and then creating anonymous classes extending LookUpFilter.
 * But since PHP doesnt support such anonymous classes as java does
 * ex: <code>
 * 	anObj.attach(
 * 		new LookUpFilter(){
 * 			public boolean inFilter(Color $color){
 * 				return true;
 * 			}
 * 		}
 * 	);
 * </code>
 * I had to alter this class in the way as it is now.
 * The constructor accepts a string which is PHP code which will be eval-ed in the function inFilter.
 *
 * This makes it possible to use this class in conjuntion with a database where all filters are stored in the database. This is currently not implemented.
 *
 * @author daantimmer
 */
class Image_Lib_LookUpFilter{
	
	/**
	 * @var string
	 */
	private $filter;
	
	/**
	 * @var string
	 */
	private $color;
	
	/**
	 * private storage where the evaled code can store arbitrary stuff
	 *
	 * @var unknown_type
	 */
	private $store = array();
	
	public function __construct($filter,$color){
		$this->filter = '$hsv = array(0,0,0);
Image_Lib_Color::rgb2hsv($color->getRed(),$color->getGreen(),$color->getBlue(),$hsv);
$hsv[0] *= 360;
'."{$filter}".'
return Image_ColorIndex::instance()->NONE;';
		$this->color = $color;
	}
	
	public function inFilter(Image_Lib_Color $color){
		return eval($this->filter);
	}
	
	public function getColor(){
		return eval($this->color);
	}
}